package com.cskaoyan.order.conf;

import com.cskaoyan.order.dal.persistence.OrderMapper;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author Chen_Feng
 * @since 2022/07/10 19:37
 */
@Component
@Data
public class OrderProperties {

    @Autowired
    OrderMapper orderMapper;

    @Value("${shopping.order.open-fake-delete}")
    private boolean OPEN_FAKE_DELETE; // 删除操作是否为伪删除

    private boolean deletedFieldExist; // 数据库表中是否存在deleted字段

    @PostConstruct
    private void init() {
        Object o = orderMapper.showDeletedColumn();
        deletedFieldExist = o != null;
        if (!deletedFieldExist) {
            OPEN_FAKE_DELETE = false;
        }
    }
}
